/**
 * 
 */
package com.changil.nowonchangilchurch.common;


import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.widget.ImageView;

import com.changil.nowonchangilchurch.util.UiUtil;

/**
 * @author 홍창우
 *
 */
public class BlurTask {
	private ImageView mHolder = null;
	public interface BlurTaskListener {
		public void onBlurTaskCompleted();
	}
	private BlurTaskListener mBlurTaskListener;
	
	private BlurTask(ImageView holder){
		mHolder = holder;
	}
	
	public static BlurTask newInstance(ImageView holder) {
		return new BlurTask(holder);
	}
	
	public void setBlurTaskListener(BlurTaskListener l) {
		mBlurTaskListener = l;
	}
	
	public void execute(Bitmap source) {
		new BlurCompleteTask().execute(source);
	}
	
	class BlurCompleteTask extends AsyncTask<Bitmap, Void, Bitmap> {

        @Override
        protected Bitmap doInBackground(Bitmap... params) {
        	return UiUtil.fastBlur(params[0], 10);
        }

        @Override
        protected void onPostExecute(Bitmap result) {
            super.onPostExecute(result);
            mHolder.setImageBitmap(result);
            if(null != mBlurTaskListener) {
            	mBlurTaskListener.onBlurTaskCompleted();
            }
        }
    }
}
